package com.dlnu.shoping.shopping.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.dlnu.shoping.shopping.common.Result;
import com.dlnu.shoping.shopping.service.ILoginService;
import com.dlnu.shoping.shopping.service.impl.ILoginServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/login")
public class loginController {
    @Resource
    private ILoginService loginService;
    @RequestMapping("/login")
    public Result login(@RequestParam String name, @RequestParam String password) {
        return loginService.login(name,password);
    }

    @RequestMapping("/addUser")
    public Result addUser(@RequestParam String name, @RequestParam String password, @RequestParam String nickname){
        return loginService.addUser(name, password, nickname);
    }

    @RequestMapping("/delUser")
    public Result delUser(@RequestParam Integer userId){
        return loginService.delUser(userId);
    }

    @RequestMapping("/updatePassword")
    public Result changePassword(@RequestParam Integer userId, @RequestParam String newPassword, @RequestParam String oldPassword){
        return loginService.changePassword(userId,newPassword,oldPassword);
    }

    @RequestMapping("queryUserList")
    public Result queryUserList(@RequestParam(required = false) String username){
        return loginService.queryUserList(username);
    }

    @RequestMapping("/queryUserCount")
    public Result queryUserCount(@RequestParam(required = false) String username){
        return loginService.queryUserCount(username);
    }

    @RequestMapping("queryUserList2")
    public Result queryUserList2(@RequestParam(required = false) String username, @RequestParam(required = false) String nickname)
    {
        return loginService.queryUserList2(username,nickname);
    }

    @RequestMapping("/queryUserPage")
    public Result queryUserPage(@RequestParam(required = false) String username,
                                @RequestParam(required = false,defaultValue = "1") Integer pageNo,
                                @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        return loginService.queryUserPage(username,pageNo,pageSize);
    }

    @RequestMapping("queryUserPage2")
    public Result queryUserPage2(@RequestParam(required = false) String username,
                                 @RequestParam(required = false) String nickname,
                                 @RequestParam(required = false,defaultValue = "1") Integer pageNo,
                                 @RequestParam(required = false,defaultValue = "10") Integer pageSize)
    {
        return loginService.queryUserPage2(username,nickname,pageNo,pageSize);
    }
}
